from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2023-01-03 14:02:57.367701
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 03, Jan, 2023
Time: 14:03:03
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3570
Nobs: 890.000 HQIC: -51.6563
Log likelihood: 11793.8 FPE: 3.05873e-23
AIC: -51.8415 Det(Omega_mle): 2.76611e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296761 0.049126 6.041 0.000
L1.Burgenland 0.105833 0.033783 3.133 0.002
L1.Kärnten -0.106384 0.018143 -5.864 0.000
L1.Niederösterreich 0.213365 0.070844 3.012 0.003
L1.Oberösterreich 0.081700 0.066980 1.220 0.223
L1.Salzburg 0.250389 0.035883 6.978 0.000
L1.Steiermark 0.029724 0.047093 0.631 0.528
L1.Tirol 0.126520 0.038290 3.304 0.001
L1.Vorarlberg -0.060181 0.032893 -1.830 0.067
L1.Wien 0.066443 0.059717 1.113 0.266
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061656 0.100818 0.612 0.541
L1.Burgenland -0.009424 0.069330 -0.136 0.892
L1.Kärnten 0.049296 0.037233 1.324 0.186
L1.Niederösterreich -0.170374 0.145388 -1.172 0.241
L1.Oberösterreich 0.360404 0.137458 2.622 0.009
L1.Salzburg 0.285917 0.073640 3.883 0.000
L1.Steiermark 0.107532 0.096645 1.113 0.266
L1.Tirol 0.319205 0.078580 4.062 0.000
L1.Vorarlberg 0.025150 0.067503 0.373 0.709
L1.Wien -0.023538 0.122553 -0.192 0.848
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201916 0.025565 7.898 0.000
L1.Burgenland 0.090563 0.017580 5.151 0.000
L1.Kärnten -0.008899 0.009441 -0.943 0.346
L1.Niederösterreich 0.266717 0.036866 7.235 0.000
L1.Oberösterreich 0.110545 0.034855 3.172 0.002
L1.Salzburg 0.053604 0.018673 2.871 0.004
L1.Steiermark 0.015985 0.024506 0.652 0.514
L1.Tirol 0.101595 0.019926 5.099 0.000
L1.Vorarlberg 0.057247 0.017117 3.345 0.001
L1.Wien 0.111745 0.031076 3.596 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.106758 0.026245 4.068 0.000
L1.Burgenland 0.047896 0.018048 2.654 0.008
L1.Kärnten -0.016489 0.009693 -1.701 0.089
L1.Niederösterreich 0.197335 0.037847 5.214 0.000
L1.Oberösterreich 0.276835 0.035783 7.737 0.000
L1.Salzburg 0.117727 0.019170 6.141 0.000
L1.Steiermark 0.100964 0.025158 4.013 0.000
L1.Tirol 0.125279 0.020456 6.124 0.000
L1.Vorarlberg 0.070064 0.017572 3.987 0.000
L1.Wien -0.027120 0.031903 -0.850 0.395
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.133849 0.047200 2.836 0.005
L1.Burgenland -0.053646 0.032458 -1.653 0.098
L1.Kärnten -0.036422 0.017431 -2.089 0.037
L1.Niederösterreich 0.165830 0.068066 2.436 0.015
L1.Oberösterreich 0.131440 0.064353 2.042 0.041
L1.Salzburg 0.290491 0.034476 8.426 0.000
L1.Steiermark 0.034392 0.045246 0.760 0.447
L1.Tirol 0.159890 0.036789 4.346 0.000
L1.Vorarlberg 0.109009 0.031603 3.449 0.001
L1.Wien 0.066779 0.057375 1.164 0.244
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.066329 0.037520 1.768 0.077
L1.Burgenland 0.038067 0.025801 1.475 0.140
L1.Kärnten 0.049958 0.013856 3.605 0.000
L1.Niederösterreich 0.225516 0.054106 4.168 0.000
L1.Oberösterreich 0.266962 0.051155 5.219 0.000
L1.Salzburg 0.060658 0.027405 2.213 0.027
L1.Steiermark -0.006519 0.035967 -0.181 0.856
L1.Tirol 0.157395 0.029244 5.382 0.000
L1.Vorarlberg 0.068112 0.025121 2.711 0.007
L1.Wien 0.074382 0.045608 1.631 0.103
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189763 0.045080 4.210 0.000
L1.Burgenland 0.017014 0.031000 0.549 0.583
L1.Kärnten -0.058886 0.016648 -3.537 0.000
L1.Niederösterreich -0.095944 0.065009 -1.476 0.140
L1.Oberösterreich 0.178123 0.061463 2.898 0.004
L1.Salzburg 0.061528 0.032927 1.869 0.062
L1.Steiermark 0.226385 0.043214 5.239 0.000
L1.Tirol 0.483654 0.035136 13.765 0.000
L1.Vorarlberg 0.051298 0.030183 1.700 0.089
L1.Wien -0.051107 0.054798 -0.933 0.351
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153590 0.050934 3.015 0.003
L1.Burgenland -0.001080 0.035026 -0.031 0.975
L1.Kärnten 0.067086 0.018810 3.566 0.000
L1.Niederösterreich 0.201836 0.073451 2.748 0.006
L1.Oberösterreich -0.068567 0.069445 -0.987 0.323
L1.Salzburg 0.220803 0.037203 5.935 0.000
L1.Steiermark 0.108260 0.048825 2.217 0.027
L1.Tirol 0.083902 0.039699 2.113 0.035
L1.Vorarlberg 0.127417 0.034103 3.736 0.000
L1.Wien 0.108035 0.061914 1.745 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357149 0.030169 11.838 0.000
L1.Burgenland 0.008240 0.020747 0.397 0.691
L1.Kärnten -0.025396 0.011142 -2.279 0.023
L1.Niederösterreich 0.229325 0.043506 5.271 0.000
L1.Oberösterreich 0.150694 0.041133 3.664 0.000
L1.Salzburg 0.052750 0.022036 2.394 0.017
L1.Steiermark -0.016604 0.028920 -0.574 0.566
L1.Tirol 0.121689 0.023515 5.175 0.000
L1.Vorarlberg 0.073388 0.020200 3.633 0.000
L1.Wien 0.050200 0.036673 1.369 0.171
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039114 0.164544 0.183945 0.171418 0.147205 0.130891 0.068306 0.220899
Kärnten 0.039114 1.000000 0.002574 0.132298 0.027470 0.098955 0.430330 -0.048544 0.101682
Niederösterreich 0.164544 0.002574 1.000000 0.351726 0.175274 0.319582 0.136332 0.194059 0.342850
Oberösterreich 0.183945 0.132298 0.351726 1.000000 0.238879 0.346995 0.186325 0.181283 0.274318
Salzburg 0.171418 0.027470 0.175274 0.238879 1.000000 0.158785 0.142336 0.154547 0.142630
Steiermark 0.147205 0.098955 0.319582 0.346995 0.158785 1.000000 0.167766 0.149846 0.098673
Tirol 0.130891 0.430330 0.136332 0.186325 0.142336 0.167766 1.000000 0.125970 0.165119
Vorarlberg 0.068306 -0.048544 0.194059 0.181283 0.154547 0.149846 0.125970 1.000000 0.021511
Wien 0.220899 0.101682 0.342850 0.274318 0.142630 0.098673 0.165119 0.021511 1.000000